--
-- Author: ping.wang
-- Date: 2019-07-02 16:33:55
--
local fileName = string.getModeName(...)
local ClassRef = class(fileName)
local table_insert = table.insert
local math_clamp = math.clamp
local string_format = string.format
function ClassRef:ctor(data)
    if data then
        self:init(data)
    end
end


function ClassRef:init(msg)
    self.haveGet = msg.receive
    self.canGet = msg.canGet
    self.equipScoreSum = msg.equipScoreSum --历史最高装备评分和
    self.strengthLevelSum = msg.strengthLevelSum --历史最高装备强化等级和
    self.jewelScoreSum = msg.jewelScoreSum --历史最高宝石评分和
    self.mountStarSum = msg.mountStarSum --历史最高坐骑星级和
    self.mountMinRank = msg.mountMinRank --坐骑最小品质
    self.conformMountNum = msg.conformMountNum --符合坐骑最小品质的坐骑数量
    self.corePointNum = msg.corePointNum --核心点数
    self.id = msg.id
    self.bestCombat = msg.bestCombat --历史最高战力
    --根据最高战力得到相关配置信息
    self.conf = GD:getDirectoryChallengeFightByPw(self.bestCombat)
    self.lvConf = GD:getDirectoryChallengeLvInfo(self.id)
end

--获取历史最高战力
function ClassRef:getMaxCombatPower()
    return self.bestCombat
end

function ClassRef:getConfMaxPw()
    return tonumber(self.conf.combatMax)
end

--获取当前的进度值 0-100，以及值文本
function ClassRef:getProgressPwAndString()
    if self.bestCombat >= self:getConfMaxPw() then
        return 100, tostring(self.bestCombat)
    else
        local str = string.format("%s/%s",tostring(self.bestCombat),self.conf.combatMax)
        return math.floor(100 * self.bestCombat/self:getConfMaxPw()), str
    end
end

function ClassRef:getCombatPowerLvName()
    return self.conf.levelName
end

--根据当前战力获取掉落外观
function ClassRef:getDropAtCurrentPw()
    return self.conf.drop
end


function ClassRef:getLvInfo()
    return self.lvConf
end

--判断当前挑战是否是最后一个
function ClassRef:isMaxChallenge()
    local infos = GD:getAllDirectoryChallengeLvInfos()
    return tonumber(infos[#infos].ID) == self.id
end

function ClassRef:getPercentByIdx(idx)
    if idx == 1 then
        return math_clamp(self.equipScoreSum/tonumber(self.lvConf.equipScoreSum),0,1)
    elseif idx == 2 then
        return math_clamp(self.strengthLevelSum/tonumber(self.lvConf.strengthLevelSum),0,1)
    elseif idx == 3 then
        return math_clamp(self.jewelScoreSum/tonumber(self.lvConf.jewelScoreSum),0,1)
    elseif idx == 4 then
        return math_clamp(self.mountStarSum/tonumber(self.lvConf.mountStarSum),0,1)
    elseif idx == 5 then
        return math_clamp(self.conformMountNum/tonumber(self.lvConf.conformMountNum),0,1)
    elseif idx == 6 then
        if checknumber(self.lvConf.corePointNum) > 0 then
            return math_clamp(self.corePointNum/tonumber(self.lvConf.corePointNum),0,1)
        end
    end
    return nil
end

--type, percent, desc
function ClassRef:getChallengeData()
    local data = {}
    table_insert(data,
        {
            type = 1,
            percent = self:getPercentByIdx(1) * 100,
            desc = string_format(L(self.lvConf.desc1),self.lvConf.equipScoreSum)
        })
    table_insert(data,
        {
            type = 2,
            percent = self:getPercentByIdx(2) * 100,
            desc = string_format(L(self.lvConf.desc2),self.lvConf.strengthLevelSum)
        })
    table_insert(data,
        {
            type = 3,
            percent = self:getPercentByIdx(3) * 100,
            desc = string_format(L(self.lvConf.desc3),self.lvConf.jewelScoreSum)
        })
    table_insert(data,
        {
            type = 4,
            percent = self:getPercentByIdx(4) * 100,
            desc = string_format(L(self.lvConf.desc4),self.lvConf.mountStarSum)
        })

    local str1 = L(string_format("Quality_String_%s",self.lvConf.mountMinRank))
    table_insert(data,
        {
            type = 5,
            percent = self:getPercentByIdx(5) * 100,
            desc = string_format(L(self.lvConf.desc5), str1, self.lvConf.conformMountNum)
        })
    if checknumber(self.lvConf.corePointNum) > 0 then
        table_insert(data,
            {
                type = 6,
                percent = self:getPercentByIdx(6) * 100,
                desc = string_format(L(self.lvConf.desc6), self.lvConf.corePointNum)
            })
    end

    return data
end
return ClassRef